
package com.xiaoma.myaudience.biz.model;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;

import com.xiaoma.myaudience.util.model.BaseColumnInfo;

public class PlayRecordNoLoginInfo extends BaseColumnInfo {
    public static final String END_TAG_OVER = "1";
    public static final String END_TAG_NOT_OVER = "0";
    
    public static final String PID = "pid";

    public static final String VID = "vid";
    
    public static final String TITLE = "title";

    public static final String VNUMBER = "vnumber";

    public static final String WATCH_TIME = "watchtime";

    public static final String TIME_SPAN = "timespan";

    public static final String END_TAG = "endtag";

    public String mRid;

    public String mPid;

    public String mVid;

    public String mTitle;

    public int mVnumber = -1;

    public String mWatchTime;

    public String mTimeSpan;

    public String mEndTag;

    
    @Override
    public ContentValues generateContentValues() {
        ContentValues values = super.generateContentValues();
        values.put(PID, mPid);
        values.put(VID, mVid);
        values.put(TITLE, mTitle);
        if (mVnumber != -1) {
            values.put(VNUMBER, mVnumber);
        }
        values.put(WATCH_TIME, mWatchTime);
        values.put(TIME_SPAN, mTimeSpan);
        values.put(END_TAG, mEndTag);
        return values;
    }

    @Override
    public void readFromCursor(Cursor cursor) {
        super.readFromCursor(cursor);
        int index = -1;
        if ((index = cursor.getColumnIndex(PID)) != -1) {
            mPid = cursor.getString(index);
            index = -1;
        }
        if ((index = cursor.getColumnIndex(VID)) != -1) {
            mVid = cursor.getString(index);
            index = -1;
        }
        if ((index = cursor.getColumnIndex(TITLE)) != -1) {
            mTitle = cursor.getString(index);
            index = -1;
        }
        if ((index = cursor.getColumnIndex(VNUMBER)) != -1) {
            mVnumber = cursor.getInt(index);
            index = -1;
        }
        if ((index = cursor.getColumnIndex(WATCH_TIME)) != -1) {
            mWatchTime = cursor.getString(index);
            index = -1;
        }
        if ((index = cursor.getColumnIndex(TIME_SPAN)) != -1) {
            mTimeSpan = cursor.getString(index);
            index = -1;
        }
        if ((index = cursor.getColumnIndex(END_TAG)) != -1) {
            mEndTag = cursor.getString(index);
            index = -1;
        }

    }

    @Override
    public void readFromJSONObject(JSONObject o) throws JSONException {
        super.readFromJSONObject(o);
        if (o != null) {
            if (o.has(PID))
                mPid = o.getString(PID);
            if (o.has(VID))
                mVid = o.getString(VID);
            if (o.has(TITLE))
                mTitle = o.getString(TITLE);
            if (o.has(VNUMBER))
                mVnumber = o.getInt(VNUMBER);
            if (o.has(WATCH_TIME))
                mWatchTime = o.getString(WATCH_TIME);
            if (o.has(TIME_SPAN))
                mTimeSpan = o.getString(TIME_SPAN);
            if (o.has(END_TAG))
                mEndTag = o.getString(END_TAG);
        }
    }

    @Override
    public void readFromParcel(Parcel source) {
        super.readFromParcel(source);
        mRid = source.readString();
        mPid = source.readString();
        mVid = source.readString();
        mTitle = source.readString();
        mVnumber = source.readInt();
        mWatchTime = source.readString();
        mTimeSpan = source.readString();
        mEndTag = source.readString();
    }

    @Override
    public void writeToParcel(Parcel parcel, int paramInt) {
        super.writeToParcel(parcel, paramInt);
        parcel.writeString(mRid);
        parcel.writeString(mPid);
        parcel.writeString(mVid);
        parcel.writeString(mTitle);
        parcel.writeInt(mVnumber);
        parcel.writeString(mWatchTime);
        parcel.writeString(mTimeSpan);
        parcel.writeString(mEndTag);
    }

    public static final Parcelable.Creator<PlayRecordNoLoginInfo> CREATOR = new Creator<PlayRecordNoLoginInfo>() {
        public PlayRecordNoLoginInfo createFromParcel(Parcel source) {
            PlayRecordNoLoginInfo info = new PlayRecordNoLoginInfo();
            info.readFromParcel(source);
            return info;
        }

        public PlayRecordNoLoginInfo[] newArray(int size) {
            return new PlayRecordNoLoginInfo[size];
        }
    };

}
